package com.hhit.zhgd.config

import cn.dev33.satoken.config.SaTokenConfig
import cn.dev33.satoken.`fun`.SaFunction
import cn.dev33.satoken.`fun`.SaParamFunction
import cn.dev33.satoken.interceptor.SaInterceptor
//import cn.dev33.satoken.jwt.StpLogicJwtForSimple
import cn.dev33.satoken.router.SaRouter
import cn.dev33.satoken.stp.StpLogic
import cn.dev33.satoken.stp.StpUtil
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.web.servlet.config.annotation.InterceptorRegistry
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer

@Configuration
class MySaTokenConfig:WebMvcConfigurer {
//    @Bean
//    fun saTokenConfig():SaTokenConfig {
//        val saTokenConfig = SaTokenConfig()
//        saTokenConfig.tokenName = "satoken"
//        saTokenConfig.timeout = 86400L
////        saTokenConfig.activeTimeout = 3600L
//        saTokenConfig.isConcurrent = true
//        saTokenConfig.tokenStyle = "uuid"
//        return saTokenConfig
//    }

//    @Bean
//    fun getStpLogicJwt():StpLogic {
//        return StpLogicJwtForSimple()
//    }

//    override fun addInterceptors(registry: InterceptorRegistry) {
//        registry.addInterceptor(SaInterceptor {
//            SaRouter.match("/**")
//                .notMatch("/login","/exportWord","/getProjectInfo","/analysis/service/frontAnalyse","/pauseTask","/updateTask","/resumeTask","/stopTask")
//                .check(SaFunction {
//                StpUtil.checkLogin()
//            })
//        }).addPathPatterns("/**")
//    }

    override fun addInterceptors(registry: InterceptorRegistry) {
        val s = registry.addInterceptor(SaInterceptor {handler ->
            SaRouter.match("/**")
                .notMatch("/login", "/exportWord", "/getProjectInfo", "/analysis/service/frontAnalyse", "/pauseTask", "/updateTask", "/resumeTask", "/stopTask")
                .check(SaParamFunction {
                    StpUtil.checkLogin()
                })
        })
        s.addPathPatterns("/**")
    }

}